<?php

class RenderMapXML
{

  public function genFloodMapXML ($flooddata)
  {
    //var_dump($flooddata);
    //Gen XML
    $xml = new DOMDocument('1.0', 'UTF-8');
    $xml->formatOutput = true;
    $xml_node_datas = $xml->createElement("datas");
    $xml->appendChild($xml_node_datas);
    $count = 1;
    foreach ($flooddata['layer'] as $val)
    {
      /*
              if(($count % 10) == 0){
                $icon = "http://maps.gstatic.com/intl/th_ALL/mapfiles/ms/micons/caution.png";
              }else if(($count % 15) == 0){
                $icon = "http://maps.gstatic.com/intl/th_ALL/mapfiles/ms/micons/firedept.png";
              }else{
                $icon = $val['icon'];
              }
*/
      $icon = $val['icon'];
      ////////////////////////////////////////////////
      //XML : node Map
      ////////////////////////////////////////////////
      $xml_node_data = $xml->createElement("data");
      $xml_node_data->setAttribute("id", $count ++);
      $xml_node_datas->appendChild($xml_node_data);
      $xml_node_title = $xml->createElement("title", $val['title']);
      $xml_node_data->appendChild($xml_node_title);
      $xml_node_description = $xml->createElement("description", 
      $val['description']);
      $xml_node_data->appendChild($xml_node_description);
      $xml_node_icon = $xml->createElement("icon", $icon);
      $xml_node_data->appendChild($xml_node_icon);
      $xml_node_detail = $xml->createElement("detail", $val['detail']);
      $xml_node_data->appendChild($xml_node_detail);
      $xml_node_latitude = $xml->createElement("latitude", 
      $val['latitude']);
      $xml_node_data->appendChild($xml_node_latitude);
      $xml_node_longitude = $xml->createElement("longitude", 
      $val['longitude']);
      $xml_node_data->appendChild($xml_node_longitude);
    }
    echo $xml->saveXML();
  }
}
?>